<?php
/** require:
 *  __PHY_LIB
 */
require_once(__PHY_LIB . "/class/Item.class.php");

class Guest extends Item {
/// definition and constructor ///
	function Guest($id=0, $field="") {
		Query::Query();
		$this->cfgKeyField("id");
		$this->cfgAllField("id,last_time");
		$this->cfgTable("unit_guest");
		if ("" == $field || "*" == $field) {
			$this->cfgField($this->mAllField);
		}
		else {
			$this->cfgField($field);
		}
		if (0 < $id) {
			$this->cfgWhere($this->mKeyField . "=" . $id);
			$this->load();
		}
		else {
			$this->set($this->mKeyField, $id);
		}
	}

	function invalid() {
		return false;
	}

	function createNew() {
		$oOne = new Guest();
		$oOne->set('last_time', date('Y-m-d H:i:s'));
		$oOne->insert();
		return $oOne;
	}

	function saveCookie() {
		$nExpire = time() + 86400*7;
		setcookie('u_type', 'guest',        $nExpire, '/'); $_COOKIE['u_type'] = 'guest';
		setcookie('u_id',   $this->getID(), $nExpire, '/'); $_COOKIE['u_id']   = $this->getID();
		setcookie('u_nick', $this->getID(), $nExpire, '/'); $_COOKIE['u_nick'] = $this->getID();
	}

} /// end class Guest.


class GuestList extends ItemList {
	/// definition and constructor ///
	function GuestList($tablename=null) {
		ItemList::ItemList();
		$this->cfgClass("Guest");
		$this->cfgKeyField("id");
		$this->cfgAllField("id,last_time");
		$this->cfgTable(null == $tablename ? "unit_guest" : $tablename);
	}

} /// end class GuestList.
?>
